//
//  NSOperatgion_CZYNJT_VC.m
//  DXC
//
//  Created by TOPTEAM on 2017/5/9.
//  Copyright © 2017年 TOPTEAM. All rights reserved.
//

#import "NSOperatgion_CZYNJT_VC.h"

@interface NSOperatgion_CZYNJT_VC ()

@end

@implementation NSOperatgion_CZYNJT_VC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"NSOperation操作依赖和监听";
    self.view.backgroundColor=[UIColor whiteColor];
    // Do any additional setup after loading the view.
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    //1.创建队列
    NSOperationQueue *queue = [[NSOperationQueue alloc]init];
    NSOperationQueue *queue1 = [[NSOperationQueue alloc]init];
    //2.封装操作
    NSBlockOperation *op1 = [NSBlockOperation blockOperationWithBlock:^{
        NSLog(@"1----%@",[NSThread currentThread]);
        
    }];
    NSBlockOperation *op2 = [NSBlockOperation blockOperationWithBlock:^{
        NSLog(@"2----%@",[NSThread currentThread]);
        
    }];
    NSBlockOperation *op3 = [NSBlockOperation blockOperationWithBlock:^{
        NSLog(@"3----%@",[NSThread currentThread]);
        
    }];
    NSBlockOperation *op4 = [NSBlockOperation blockOperationWithBlock:^{
        NSLog(@"4----%@",[NSThread currentThread]);
        
    }];
    NSBlockOperation *op5 = [NSBlockOperation blockOperationWithBlock:^{
        for (NSInteger i=0; i<10000; i++) {
            NSLog(@"5-%zd---%@",i,[NSThread currentThread]);
        }
        
        
    }];
    
    op4.completionBlock = ^{
        NSLog(@"op4已经完成了---%@",[NSThread currentThread]);
    };
    
    //添加操作依赖,注意不能循环依赖
    [op1 addDependency:op5];
    [op1 addDependency:op4];
    
    //添加操作到队列
    [queue addOperation:op1];
    [queue addOperation:op2];
    [queue addOperation:op3];
    [queue addOperation:op4];
    [queue1 addOperation:op5];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
